package com.dailyblue.java.project.smbms.address.controller;

import com.dailyblue.java.commons.util.JsonResult;
import com.dailyblue.java.project.smbms.address.bean.Address;
import com.dailyblue.java.project.smbms.address.service.AddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/address")
@CrossOrigin
public class AddressController {
    @Resource
    private AddressService addressService;
    @GetMapping("/{contact}/{addressDesc}/{postCode}/{tel}/{userId}")
    public JsonResult save(@PathVariable("contact") String contact,@PathVariable("addressDesc") String addressDesc,@PathVariable("postCode") String postCode,@PathVariable("tel") String tel,@PathVariable("userId") int userId){
        Address address = new Address(contact,addressDesc,postCode,tel,userId,1);
        return addressService.saveAddress(address);
    }
    @GetMapping("/{id}")
    public JsonResult find(@PathVariable("id")int userId){
        return addressService.findAddressByUserId(userId);
    }
}
